#pragma once

#include "ServiceProvider.h"

#include <sstream>

class LeagueManager;
class UserManager;
class AuctionManager;
class TeamManager;
class PlayerManager;
class NameManager;
class GameAI;
class Settings;
class EventGenerator;

class GameManager : public ServiceProvider
{
public:

	GameManager();
	~GameManager();

	// game controls
	bool Save(const char* const filename);
	bool Load(const char* const filename);
	void Restart();
	void Simulate(const bool i_doNotPrompt = false);
	void EndSeason(const bool i_doNotPrompt, std::stringstream& o_message);

	// service provider
	virtual TeamManager&	GetTeamMgr();
	virtual PlayerManager&	GetPlayerMgr();
	virtual AuctionManager&	GetAuctionMgr();
	virtual NameManager&	GetNameMgr();
	virtual UserManager&	GetUserMgr();
	virtual const Settings&	GetSettings() const;
	virtual	LeagueManager& GetLeagueMgr() const;
	virtual	const GameAI&	GetAI() const;
	virtual	const EventGenerator&	GetMatchEventGenerator() const;

private:

	GameManager(const GameManager&);
	GameManager operator=(const GameManager&);

	void Initialize();
	void Clear();

	void PreMatchUpdate(const bool i_doNotPrompt);
	void Update(const bool i_doNotPrompt);
	void PostMatchUpdate(const bool i_doNotPrompt);

	LeagueManager*	m_leagueManager;
	UserManager*	m_userManager;
	AuctionManager*	m_auctionManager;
	TeamManager*	m_teamManager;
	PlayerManager*	m_playerManager;
	NameManager*	m_nameManager;
	GameAI*		m_ai;
	Settings*		m_settings;
	EventGenerator*	m_matchEventGenerator;

	int				m_seed;
};

inline UserManager&	GameManager::GetUserMgr()
{
	return *m_userManager;
}

inline AuctionManager& GameManager::GetAuctionMgr()
{
	return *m_auctionManager;
}

inline TeamManager&	GameManager::GetTeamMgr()
{
	return *m_teamManager;
}

inline PlayerManager& GameManager::GetPlayerMgr()
{
	return *m_playerManager;
}

inline NameManager&	GameManager::GetNameMgr()
{
	return *m_nameManager;
}

inline const GameAI& GameManager::GetAI() const
{
	return *m_ai;
}

inline const Settings& GameManager::GetSettings() const
{
	return *m_settings;
}

inline LeagueManager& GameManager::GetLeagueMgr() const
{
	return *m_leagueManager;
}

inline const EventGenerator& GameManager::GetMatchEventGenerator() const
{
	return *m_matchEventGenerator;
}
